<?php
class XlsModel extends Action{
	//test
	//
	//############test
	public function export($thls,$mls,$filenm){
		$info=collectinfo(__METHOD__,'$thls,$mls,$filenm',array($thls,$mls,$filenm));
		if(isset($thls)===false){return createarrerr('error_code','thls 不能为空',$info);}//防止NULL
		if(isset($mls)===false){return createarrerr('error_code','mls 不能为空',$info);}//防止NULL
		if(isset($filenm)===false){return createarrerr('error_code','filenm 不能为空',$info);}//防止NULL

		import('@.ORG.PHPExcel');
    	// Create new PHPExcel object
    	$objPHPExcel = new PHPExcel();
    	// Set properties
    	$objPHPExcel->getProperties()->setCreator("ctos")
    	->setLastModifiedBy("ctos")
    	->setTitle("Office 2007 XLSX Test Document")
    	->setSubject("Office 2007 XLSX Test Document")
    	->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
    	->setKeywords("office 2007 openxml php")
    	->setCategory("Test result file");

    	// set table header content列是从0开始，行是从1开始
    	$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(10);
    	$sheet=$objPHPExcel->setActiveSheetIndex(0);
    	$sheet=$sheet->setCellValueByColumnAndRow(0,1,'序号');
    	
        $i=0;
        foreach($thls as $thv){
            $sheet=$sheet->setCellValueByColumnAndRow($i+1,1,$thv);
            $i=$i+1;
        }
    	    	
    	for($j=0;$j<count($mls);$j++){
    		$sheet=$sheet->setCellValueByColumnAndRow(0,$j+2,$j+1);
    		$mo=$mls[$j];
    		$i=0;
 			foreach($mo as $k=>$v){
                if($k=='stdidcd'||$k=='stdno'){
     				$sheet=$sheet->setCellValueByColumnAndRow($i+1,$j+2,$v.' ');
                }else{
                    $sheet=$sheet->setCellValueByColumnAndRow($i+1,$j+2,$v);
                }
 				$i=$i+1;
    		}
    	}
    	
    	
    	
    	
    	// Set active sheet index to the first sheet, so Excel opens this as the first sheet
    	$objPHPExcel->setActiveSheetIndex(0);
    	
    	
    	// excel头参数
    	header('Content-Type: application/vnd.ms-excel');
    	header("Content-Disposition: attachment;filename=".$filenm.date("Ymd-His",time()).".xls");  //日期为文件名后缀
    	header('Cache-Control: max-age=0');
    	
    	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');  //excel5为xls格式，excel2007为xlsx格式
    	$objWriter->save('php://output');

		return createarrok('ok',$data,'',$info);
	}
	

} 
?>